﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using OpSystem.manage;
using OpSystem.common;
using OF.Component.Model;
using OF.Component.BLL;

namespace OpSystem.Manage.InfoManage
{
    public partial class Authorityuserlist : BasePage
    {
        protected int intCount = 0;
        protected string strName = "";
        protected Dictionary<int, List<string>> dic = new Dictionary<int, List<string>>();
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPageCode("10104");
            if (!Page.IsPostBack)
            {
                MyBind();
            }
        }

        private void MyBind()
        {
            string where = "1=1 and IsActive=1";
           // strName = RequestUtility.GetQueryString("name");
            if (strName != "")
            {
                where += " and charindex('" + strName + "',[OpUserName])>0";
            }
            List<int> intUserId = new List<int>();

            IList<AuthorityUserInforInfo> list = AuthorityUserInforOperate.Search(out intCount, AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, where, "UserID", true);
            foreach (var item in list)
            {
                intUserId.Add(item.UserID);
            }
            dic = AuthorityUserRoleRelaOperate.GetUserRoleListNameByUserIds(intUserId);
            AspNetPager1.RecordCount = intCount;
            this.rptList.DataSource = list;
            this.rptList.DataBind();
        }

        /// <summary>
        /// 获取角色名称
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        protected string GetRoleNameByUserId(int userId)
        {
            if (dic.ContainsKey(userId))
            {
                List<string> userList = (List<string>)dic[userId];
                return string.Join(",", userList.ToArray());
            }
            return "";
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            MyBind();
        }

    }
}